//
//  QiYeXinXiZhanShiVC.m
//  EnterpriseEdition
//
//  Created by ypj on 2021/10/9.
//
#define  SignImageHeight  (ScreenWidth-32.0)/3.0-14.0+40

#import "QiYeXinXiZhanShiVC.h"
#import "UploadSignImageView.h"
#import "TiShiSignMessageView.h"
#import "QiYeLeiXingView.h"
#import "TiShiMoreMessageView.h"
#import "UplodaImageWithGongSi.h"
#import <Photos/Photos.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import "CheLiangGuiMoTableViewCell.h"
#import "QiYeModel.h"
#import "DetailAddressTableViewCell.h"
@interface QiYeXinXiZhanShiVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView             *tableView;
@property(nonatomic,strong) NSMutableArray          *dataSource;
@property(nonatomic,strong) NSMutableArray          *iconArray;
@property(nonatomic,strong) NSString                *vipMoneyType;
@property(nonatomic,strong) UplodaImageWithGongSi   *imageView;
@property(nonatomic,strong) CommonChoseTypeRoleView *choseTypeView;

@property(nonatomic,strong) NSMutableArray    *imageDataArray;
@property(nonatomic,strong) NSMutableArray    *cacheSaveFilePath;
@property(nonatomic,strong) UIImage           *YYZZImage;//营业执照
@property(nonatomic,strong) UIImage           *WTSImage;//委托书
@property(nonatomic,strong) UIImage           *GSLOImage;//公司logo
@property(nonatomic,strong) UIImage           *DLYYImage;//道路运输经营许可证
@property(nonatomic,strong) UIImage           *QCJYImage;//汽车经营许可证
@property(nonatomic,assign) NSInteger         pageTage;
@property(nonatomic,strong) YLUserInfo        *info;//用户信息
@property(nonatomic,assign) NSInteger         leftIndex;
@property(nonatomic,assign) NSInteger         centerIndex;
@property(nonatomic,assign) NSInteger         rightIndex;

@property(nonatomic,strong) NSString         *enterpriseType;//企业类型
@property(nonatomic,strong) NSString         *businessLicenseUrl;//营业执照
@property(nonatomic,strong) NSString         *enterpriseName;//企业全称
@property(nonatomic,strong) NSString         *socialCreditCode;//社会信用代码
@property(nonatomic,strong) NSString         *enterpriseLocation;//企业所在地
@property(nonatomic,strong) NSString         *enterpriseAddress;//企业详细地址
@property(nonatomic,strong) NSString         *vehicleScale;//车辆规模
@property(nonatomic,strong) NSString         *enterprisePhone;//公司联系方式
@property(nonatomic,strong) NSString         *logoUrl;//公司logo
@property(nonatomic,strong) NSString         *enterprisePhoto;//公司描述图
@property(nonatomic,strong) NSString         *proxyStatementUrl;//委托书
@property(nonatomic,strong) NSString         *transportationLicenseUrl;//道路运输许可证
@property(nonatomic,strong) NSString         *taxiOperationLicenseUrl;//出租车经营许可证url
@property(nonatomic,strong) NSMutableArray   *vehicleScaleArray;
@property(nonatomic,strong) NSString         *quanXianString;

@end

@implementation QiYeXinXiZhanShiVC
-(void)viewWillAppear:(BOOL)animated{
     [super viewWillAppear:animated];

    [self layoutCustomNav:self.view title:@"信息展示"];
    
}
-(void)viewDidLoad {
    [super viewDidLoad];
     self.info = [YLUserMgr fetchUser];
    self.quanXianString = kUserDefaultForKey(EduitString_key);
     self.vehicleScaleArray = [NSMutableArray array];
    [self getdetail];
    [self getCheLiangGuiMo];

//  self.dataSource=[NSMutableArray arrayWithArray:@[@"企业全称",@"统一社会信用码",@"企业所在地",@"企业详细地址",@"车辆规模",@"公司联系方式"]];
    self.dataSource=[NSMutableArray arrayWithArray:@[@"企业全称",@"统一社会信用码",@"企业详细地址",@"车辆规模",@"公司联系方式"]];

    self.imageDataArray = [NSMutableArray arrayWithArray:@[@"addPhoto_icon"]];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, LL_StatusBarAndNavigationBarHeight, ScreenWidth, B_HEIGHT-LL_StatusBarAndNavigationBarHeight) style:UITableViewStyleGrouped];
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.backgroundColor = White_Color;
    self.tableView.separatorColor = White_Color;
   [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:[CommonTableViewCell reuseIdentifier] bundle:nil] forCellReuseIdentifier:[CommonTableViewCell reuseIdentifier]];
    [self.tableView registerNib:[UINib nibWithNibName:[CheLiangGuiMoTableViewCell reuseIdentifier] bundle:nil] forCellReuseIdentifier:[CheLiangGuiMoTableViewCell reuseIdentifier]];
    [self.tableView registerNib:[UINib nibWithNibName:[DetailAddressTableViewCell reuseIdentifier] bundle:nil] forCellReuseIdentifier:[DetailAddressTableViewCell reuseIdentifier]];
    CGRect frame = CGRectMake(0, 0, 0, 0.1);
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:frame];
    if(@available(iOS 11.0, *)){
            self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
    } else {
            self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

-(void)createUploadImage{
   
    if (self.enterprisePhoto.length > 0 && ![self.enterprisePhoto isEqualToString:@"null"]){
         NSArray *cacheArray = [self.enterprisePhoto componentsSeparatedByString:@","];
         self.imageDataArray = [NSMutableArray arrayWithArray:cacheArray];
        [self.imageDataArray addObject:@"addPhoto_icon"];
         self.cacheSaveFilePath = [NSMutableArray arrayWithArray:cacheArray];
        [self.cacheSaveFilePath addObject:@""];
    } else {
         self.imageDataArray=[NSMutableArray arrayWithArray:@[@"addPhoto_icon"]];
         self.cacheSaveFilePath=[NSMutableArray arrayWithArray:@[@""]];
    }
    self.imageView=[UplodaImageWithGongSi shareInstance];
    [self.imageView setDataImageArray:self.imageDataArray];
    [self.imageView  getCollectionViewHeight];
     self.imageView.frame=CGRectMake(0, 0, ScreenWidth, self.imageView.collectionViewHeight);
    [ self.imageView setToShowImage:^(UIImage * _Nonnull image){
        if (image){
            UIWindow  * window=[BaseViewController getCurrentWindow];
            ShowBigImageWithFrameView * ImageShow = [[ShowBigImageWithFrameView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:image];
            [window addSubview:ImageShow];
        }
    }];
    [self.tableView reloadData];
    BD_WEAKSELF
    [self.imageView setToShowAlert:^{
        if ([weakSelf.quanXianString isEqualToString:EduitString]) {
            if(self.cacheSaveFilePath.count - 1 > 3){
                showAlert(@"最多上传3张公司描述图");
                return;
            }
            [weakSelf  upDateHeaderImage:105];
        }
    }];
    [self.imageView setToDelectImage:^(NSInteger index) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确定删除图片吗?" message:@"" preferredStyle:UIAlertControllerStyleAlert];

        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){

        }]];
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
            [weakSelf.imageView delectImageSure:index];
            [weakSelf.tableView reloadData];
        }]];
        [weakSelf  presentViewController:alert animated:true completion:nil];
    }];
    [self.imageView setToDelectFileUrl:^(NSInteger index){
         NSString *fileString = weakSelf.cacheSaveFilePath[index];
        [weakSelf delectUpdateInShopImg:fileString withIndex:index];
    }];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 6;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==1){
        return self.dataSource.count;
    } else {
        return 0;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
     if (indexPath.row == 3) {
        CheLiangGuiMoTableViewCell  *  cell=[self.tableView dequeueReusableCellWithIdentifier:[CheLiangGuiMoTableViewCell reuseIdentifier]];
     if (!cell){
         cell=[[CheLiangGuiMoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[CheLiangGuiMoTableViewCell reuseIdentifier]];
     }
    if (self.vehicleScale.length>0){
        cell.numberLb.text = self.vehicleScale;
    } else {
        cell.numberLb.text = @"0";
    }
    cell.selectionStyle= UITableViewCellSelectionStyleNone;
     return cell;
    }else if(indexPath.row == 2){
        DetailAddressTableViewCell *cell=[self.tableView dequeueReusableCellWithIdentifier:[DetailAddressTableViewCell reuseIdentifier]];
        if (!cell){
         cell = [[DetailAddressTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[DetailAddressTableViewCell reuseIdentifier]];
        }
        cell.selectionStyle= UITableViewCellSelectionStyleNone;
        cell.nameLb.text = self.dataSource[indexPath.row];
//        cell.addressTV.userInteractionEnabled=NO;   //禁止编辑详细地址
//        [cell.addressTV didChangeText:^(PlaceholderTextView *textView) {
//             self.enterpriseAddress=textView.text;
//        }];
        if (![NSString isNUllString:self.enterpriseAddress]){
            cell.addressTV.text = self.enterpriseAddress;
        } else {
            cell.addressTV.text = @"";
        }
        
        //修改企业注册地址
        [cell.addressTV didChangeText:^(PlaceholderTextView *textView) {
            self.enterpriseAddress = textView.text;
//            NSLog(@"%@",textView.text);
        }];
        return cell;
     } else {
        CommonTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:[CommonTableViewCell reuseIdentifier]];
        if (!cell){
         cell = [[CommonTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[CommonTableViewCell reuseIdentifier]];
     }
        cell.selectionStyle= UITableViewCellSelectionStyleNone;
        cell.nameLb.text = self.dataSource[indexPath.row];
        cell.rightImage.hidden = YES;
        cell.indexPath = indexPath;
        [cell setCurrentValueBlock:^(NSString * _Nonnull contentString, NSIndexPath * _Nonnull indexPath) {
            if (indexPath.row == 0) {
                self.enterpriseName = contentString;
            }else if (indexPath.row == 1){
                self.socialCreditCode = contentString;
            }else if (indexPath.row == 4){
                self.enterprisePhone = contentString;
            }
        }];
        switch (indexPath.row) {
            case 0:
            {
                cell.contentTF.userInteractionEnabled = NO;
                cell.contentTF.placeholder = @"请输入企业全称";
                if(![NSString isNUllString:self.enterpriseName]){
                       cell.contentTF.text = self.enterpriseName;
                   } else {
                   cell.contentTF.text = @"";
                   cell.contentTF.placeholder = @"";
                   }
            }
            break;
            case 1:
            {
                cell.contentTF.userInteractionEnabled=NO;
                cell.contentTF.placeholder = @"请输入统一社会信用码";
                if(![NSString isNUllString:self.socialCreditCode]){
                        cell.contentTF.text=self.socialCreditCode;
                    } else {
                        cell.contentTF.text = @"";
                        cell.contentTF.placeholder = @"";
                      }
            }
            break;
            case 2:
            {
//                cell.contentTF.userInteractionEnabled=NO;
//                cell.contentTF.placeholder=@"请选择企业所在地";
//                if(self.enterpriseLocation.length== 0){
//                    cell.contentTF.text=@"";
//                } else {
//                    cell.contentTF.text=self.enterpriseLocation;
//                }
            }
            break;
            case 3:
            {
               
            }
            break;
            case 4:
            {
                cell.contentTF.placeholder = @"请输入联系方式";
                cell.contentTF.keyboardType = UIKeyboardTypeASCIICapable;
                if (self.enterprisePhone.length == 0){
                    cell.contentTF.placeholder = @"请输入联系方式";
                } else {
                    cell.contentTF.text = self.enterprisePhone;
                }
            }
            break;
            default:
            break;
        }
        return cell;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 2){
        return [DetailAddressTableViewCell cellHeight];
    }else if(indexPath.row == 3){
        return [CheLiangGuiMoTableViewCell cellHeight];
    } else {
        return [CommonTableViewCell cellHeight];
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        UIView  *   headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 58)];
        QiYeLeiXingView *vipView = [[QiYeLeiXingView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 58) withTag:[self.vipMoneyType intValue]];
        [vipView setToRefreshButtonTable:^(NSInteger selectTag){
            
        }];
        vipView.typeLb.text = self.enterpriseType;
        vipView.bgView.hidden = YES;
        [headerView addSubview:vipView];
        return headerView;
    }else if(section == 2){
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SignImageHeight)];
        UploadSignImageView *logoImage = [UploadSignImageView shareInstance];
        logoImage.frame=CGRectMake(0, 0, ScreenWidth, SignImageHeight);
        logoImage.checkButton.hidden = YES;
        logoImage.titleLb.text = @"公司展示图";
        logoImage.biChuanLb.text = @"(必传)";
        UIImageView *logoBigImage = [[UIImageView alloc] init];
        if (self.logoUrl.length > 0){
            NSString *urlStr = [NSString stringWithFormat:@"%@%@",HTTP_URL,self.logoUrl];
            urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
            [logoImage.addImageButton sd_setImageWithURL:[NSURL URLWithString:urlStr] forState:UIControlStateNormal placeholderImage:Image(@"default_icon")];
            [logoBigImage sd_setImageWithURL:[NSURL URLWithString:urlStr]];
             NSLog(@"%@%@",HTTP_URL,self.logoUrl);
        }
        [logoImage.addImageButton whenTapped:^{
            if ([self.quanXianString isEqualToString:EduitString]) {
                //超级管理员可以修改企业信息
                [self upDateHeaderImage:102];
            } else {
                //非超级管理员不可以修改企业信息
                if (logoBigImage){
                    UIWindow *window = [BaseViewController getCurrentWindow];
                    ShowBigImageWithFrameView *ImageShow = [[ShowBigImageWithFrameView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:logoBigImage.image];
                    [window addSubview:ImageShow];
                }
            }
        }];
        if ([self.quanXianString isEqualToString:EduitString]){
            logoImage.delBtn.hidden = NO;
            
        }
        else {
            logoImage.delBtn.hidden = YES;
        }
        [headerView addSubview:logoImage];
        
        return headerView;
    }else if (section == 3){
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SignImageHeight)];
        UploadSignImageView *yingYeImage = [UploadSignImageView shareInstance];
        yingYeImage.frame = CGRectMake(0, 0, ScreenWidth, SignImageHeight);
        yingYeImage.checkButton.hidden = YES;
        yingYeImage.titleLb.text = @"道路运输经营许可证";
        yingYeImage.biChuanLb.text = @"(非必传)";
        UIImageView *transportationLicenseImage = [[UIImageView alloc] init];
        if (self.transportationLicenseUrl.length > 0) {
            [yingYeImage.addImageButton sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,self.transportationLicenseUrl]] forState:UIControlStateNormal placeholderImage:Image(@"default_icon")];
            [transportationLicenseImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,self.transportationLicenseUrl]]];
            yingYeImage.delBtn.hidden = NO;
        }
        [yingYeImage.delBtn whenTapped:^{
            self.transportationLicenseUrl = @"";
            yingYeImage.delBtn.hidden = YES;
            [self.tableView reloadData];
        }];
        [yingYeImage.addImageButton whenTapped:^{
            if ([self.quanXianString isEqualToString:EduitString]){
                //超级管理员可以修改企业信息
                [self upDateHeaderImage:103];
            } else {
                //非超级管理员不可以修改企业信息
                if (transportationLicenseImage){
                    UIWindow *window = [BaseViewController getCurrentWindow];
                    ShowBigImageWithFrameView *ImageShow = [[ShowBigImageWithFrameView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:transportationLicenseImage.image];
                    [window addSubview:ImageShow];
                }
            }
        }];
        
        if ([self.quanXianString isEqualToString:EduitString]){
            yingYeImage.delBtn.hidden = NO;
            
        }
        else {
            yingYeImage.delBtn.hidden = YES;
        }
        
        
        [footerView addSubview:yingYeImage];

        return footerView;
    }else if(section==4&&[self.quanXianString isEqualToString:EduitString]){
       
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 60)];
        UIButton *commitButton = [UIButton buttonWithType:UIButtonTypeCustom];
        commitButton.frame = CGRectMake(16, 9, ScreenWidth-32, 42);
        commitButton.backgroundColor = mainColor;
        commitButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
        [commitButton setTitleColor:White_Color forState:UIControlStateNormal];
        [commitButton createBordersWithColor:nil withCornerRadius:5.0 andWidth:0];
        [commitButton setTitle:@"提交" forState:UIControlStateNormal];
        [commitButton addTarget:self action:@selector(commitButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [headerView addSubview:commitButton];
        return headerView;
    } else {
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0)];
        return headerView;
    }
}
-(void)commitButtonClick{
    [self commitInfo];
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 0) {
        UIView *  footerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SignImageHeight)];
        UploadSignImageView *yingYeImage =[UploadSignImageView shareInstance];
        yingYeImage.frame = CGRectMake(0, 0, ScreenWidth, SignImageHeight);
        yingYeImage.checkButton.hidden = YES;
        yingYeImage.titleLb.text = @"营业执照";
        yingYeImage.biChuanLb.text = @"";
        UIImageView *cacheImage = [[UIImageView alloc] init];
        if (self.businessLicenseUrl.length > 0){
            NSString *urlStr = [NSString stringWithFormat:@"%@%@",HTTP_URL,self.businessLicenseUrl];
            urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
            [yingYeImage.addImageButton sd_setImageWithURL:[NSURL URLWithString:urlStr] forState:UIControlStateNormal placeholderImage:Image(@"default_icon")];
            [cacheImage sd_setImageWithURL:[NSURL URLWithString:urlStr]];
        }
        [yingYeImage.addImageButton whenTapped:^{
            if (cacheImage){
                UIWindow *window = [BaseViewController getCurrentWindow];
                ShowBigImageWithFrameView *ImageShow = [[ShowBigImageWithFrameView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:cacheImage.image];
                [window addSubview:ImageShow];
            }
        }];
        [footerView addSubview:yingYeImage];
         return footerView;
    }else if(section == 1){
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.1)];
//      UploadSignImageView  * shouQuanImage =[UploadSignImageView shareInstance];
//      shouQuanImage.frame=CGRectMake(0, 0, ScreenWidth, SignImageHeight);
//      shouQuanImage.checkButton.hidden=NO;
//      shouQuanImage.titleLb.text=@"授权委托书";
//      shouQuanImage.biChuanLb.text=@"(非必传)";
//      UIImageView  *  proxyStatementImage=[[UIImageView alloc] init];
//      if(self.proxyStatementUrl.length>0) {
//   [shouQuanImage.addImageButton sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,self.proxyStatementUrl]] forState:UIControlStateNormal   placeholderImage:Image(@"default_icon")];
//   [proxyStatementImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,self.proxyStatementUrl]]];
//
//        }
//        [shouQuanImage.addImageButton whenTapped:^{
//            if (proxyStatementImage){
//                UIWindow  * window=[BaseViewController getCurrentWindow];
//                ShowBigImageWithFrameView * ImageShow = [[ShowBigImageWithFrameView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:proxyStatementImage.image];
//                [window addSubview:ImageShow];
//            }
//        }];
//        shouQuanImage.checkButton.hidden=YES;
//        [footerView addSubview:shouQuanImage];
        return footerView;
    }else if (section == 2){
      //公司描述图片
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, self.imageView.collectionViewHeight)];
        [footerView addSubview:self.imageView];
        
        return footerView;
        
    }else if(section == 3){

        UIView *  footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SignImageHeight)];
        UploadSignImageView *yingYeImage = [UploadSignImageView shareInstance];
        yingYeImage.frame = CGRectMake(0, 0, ScreenWidth, SignImageHeight);
        yingYeImage.checkButton.hidden = YES;
        yingYeImage.titleLb.text = @"出租汽车经营资格证";
        yingYeImage.biChuanLb.text = @"(非必传)";
        UIImageView *taxiOperationLicenseImage = [[UIImageView alloc] init];
        if (self.taxiOperationLicenseUrl.length > 0) {
            [yingYeImage.addImageButton sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,self.taxiOperationLicenseUrl]] forState:UIControlStateNormal placeholderImage:Image(@"default_icon")];
            [taxiOperationLicenseImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,self.taxiOperationLicenseUrl]]];
            yingYeImage.delBtn.hidden = NO;
        }
        [yingYeImage.delBtn whenTapped:^{
            self.taxiOperationLicenseUrl = @"";
            yingYeImage.delBtn.hidden = YES;
            [self.tableView reloadData];
        }];
        [yingYeImage.addImageButton whenTapped:^{
            if ([self.quanXianString isEqualToString:EduitString]) {
                //超级管理员可以修改企业信息
                [self upDateHeaderImage:104];
            } else {
                //非超级管理员不可以修改企业信息
                if (taxiOperationLicenseImage){
                    UIWindow *window = [BaseViewController getCurrentWindow];
                    ShowBigImageWithFrameView *ImageShow = [[ShowBigImageWithFrameView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:taxiOperationLicenseImage.image];
                    [window addSubview:ImageShow];
                }
            }
        }];
        if ([self.quanXianString isEqualToString:EduitString]){
            yingYeImage.delBtn.hidden = NO;
            
        }
        else {
            yingYeImage.delBtn.hidden = YES;
        }
        [footerView addSubview:yingYeImage];
        return footerView;
    } else {
         UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 100)];
         return footerView;
    }
   
   
 }
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 58;
    } else if (section == 1){
        return 0;
    } else if (section == 2){
        return SignImageHeight;
    } else if (section == 3){
        return SignImageHeight;
    } else if (section == 4){
        return 60;
    } else {
        return 0;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return SignImageHeight;
    } else if (section == 1){
        return 0.1;
    } else if (section == 2){
        return self.imageView.collectionViewHeight;
    } else if (section == 3){
//        NSString  *  messageString=@"*上传资料要求：请上传最新出租汽车经营资格证，或加盖红色企业公章的复印件（非电子公章），请确保营业执照完整清晰，便于识别。";
//        CGFloat     sizeheight =[messageString heightForSizeWithFont:[UIFont systemFontOfSize:13.0] andWidth:ScreenWidth-32];
          return  SignImageHeight;
    }
    return 70;

}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    BD_WEAKSELF
//    if (indexPath.row==2) {
//        if ([self.quanXianString isEqualToString:EduitString]) {
//            ChoseCityViewController   *   choseVC =[[ChoseCityViewController alloc] init];
//            [choseVC setToSendValue:^(NSString * _Nonnull province, NSString * _Nonnull city, NSString * _Nonnull quString, NSInteger leftIndex, NSInteger centerIndex, NSInteger rightIndex) {
//                weakSelf.leftIndex=leftIndex;
//                weakSelf.centerIndex=centerIndex;
//                weakSelf.rightIndex=rightIndex;
//                weakSelf.enterpriseLocation=[NSString stringWithFormat:@"%@%@%@",province,city,quString];
//                [weakSelf.tableView reloadData];
//            }];
//            [self.navigationController pushViewController:choseVC animated:YES];
//        }
//
//    }else
    if (indexPath.row == 3){
        if ([self.quanXianString isEqualToString:EduitString]) {
        UIWindow *currentWindow = [BaseViewController getCurrentWindow];
         [weakSelf.view endEditing:YES];
        if(weakSelf.choseTypeView){
           [weakSelf.choseTypeView removeFromSuperview];
         }
         weakSelf.choseTypeView = [CommonChoseTypeRoleView  shareInstance];
         weakSelf.choseTypeView.frame = CGRectMake(0, 0, ScreenWidth, B_HEIGHT);
         [weakSelf.choseTypeView DataSourceToShowAlert:weakSelf.vehicleScaleArray withSelectTitle:weakSelf.vehicleScale withType:@"1" withTitle:@"请选则车辆规模"];
       
         [currentWindow addSubview:weakSelf.choseTypeView];
         [currentWindow bringSubviewToFront:weakSelf.choseTypeView];
        [weakSelf.choseTypeView setToSendValue:^(JueSeModel * _Nonnull model) {
             weakSelf.vehicleScale = model.value;
            [weakSelf.tableView reloadData];
           [weakSelf.choseTypeView removeFromSuperview];
        }];
        [weakSelf.choseTypeView.tableView reloadData];
        }
    }
    
}
#pragma mark---上传图片
-(void)upDateHeaderImage:(NSInteger)tag{
    UIAlertController *alertvc = [UIAlertController alertControllerWithTitle:@"上传照片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction *myLibraryAction = [UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            NSInteger sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
                PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
                if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
                    //相册权限受限制
                    showAlert(@"请前往设置-隐私-相机-利行租赁端-允许访问");
                    return;
                }
            }
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
             imagePickerController.modalPresentationStyle = 0;
            [imagePickerController.navigationBar setTintColor:[UIColor blackColor]];
            imagePickerController.delegate = self;
            imagePickerController.allowsEditing = NO;
            imagePickerController.sourceType = sourceType;
            imagePickerController.view.tag = tag;
            [self presentViewController:imagePickerController animated:YES completion:^{}];
        }];
        [alertvc addAction:myLibraryAction];
        UIAlertAction *daildAction = [UIAlertAction actionWithTitle:@"拍照上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        // 判断是否支持相机
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            
            NSUInteger sourceType = UIImagePickerControllerSourceTypeCamera;

            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
                PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
                if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
                    //相册权限受限制
                    showAlert(@"请前往设置-隐私-相机-利行租赁端-允许访问");
                    return;
                }
            }
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
             imagePickerController.modalPresentationStyle = 0;
            [imagePickerController.navigationBar setTintColor:[UIColor blackColor]];
            imagePickerController.delegate = self;
            imagePickerController.allowsEditing = NO;
            imagePickerController.sourceType = sourceType;
            imagePickerController.view.tag = tag;
            [self presentViewController:imagePickerController animated:YES completion:^{}];
        }
        
    }];
    [alertvc addAction:daildAction];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    }];
    [alertvc addAction:cancelAction];
    [self presentViewController:alertvc animated:YES completion:nil];
}

#pragma mark - image picker delegte
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:^{}];
     UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
     self.pageTage = picker.view.tag;
     NSMutableArray *tmpAry = [NSMutableArray array];
     NSData * data = [image compressMidQualityWithLengthLimit:kPhotoFileSize];
     UIImage * img0 = [UIImage imageWithData:data];
     YLUploadMedia * imageM = [YLUploadMedia mediaWithType:YLUploadMediaTypeJpg mediaName:nil mimeName:@"file" obj:img0];
     [tmpAry addObject:imageM];
     NSLog(@"<<-- 原尺寸:%@  新尺寸:%@  大小:%.4fMB -->>", NSStringFromCGSize(image.size), NSStringFromCGSize(img0.size),(double)data.length / 1024.0f / 1024.0f);
    [self shanChuanImageWithArray:tmpAry ];

}
-(void)shanChuanImageWithArray:(NSMutableArray *)tmpAry{
   
    
    
    [MSNetworkManager postRevertUrl:POST_UploadFile_URL params:@{@"type":@"1"} formData:tmpAry success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        if (isSuccess) {
            if (self.pageTage == 100) {
                self.businessLicenseUrl = resonseObj[@"url"];
            }else if (self.pageTage == 101){
                self.proxyStatementUrl = resonseObj[@"url"];
                [self.tableView reloadData];
            }else if (self.pageTage == 102){
                self.logoUrl = resonseObj[@"url"];
                [self.tableView reloadData];
            }else if (self.pageTage == 103){
                self.transportationLicenseUrl = resonseObj[@"url"];
                [self.tableView reloadData];
            }else if (self.pageTage == 104){
               self.taxiOperationLicenseUrl = resonseObj[@"url"];
               [self.tableView reloadData];
            } else {
                NSString  * fileString = resonseObj[@"url"];
                [self.imageView.imageArray insertObject:fileString atIndex:self.imageDataArray.count-1];
               [self.cacheSaveFilePath insertObject:fileString atIndex:self.cacheSaveFilePath.count-1];
               [self.imageView getCollectionViewHeight];
                self.imageView.height = self.imageView.collectionViewHeight;
               [self.imageView.collectionView reloadData];
            }
        }
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
        showAlert(@"网络异常,请稍后再试!");
    } withShowHud:YES];
  
}

-(void)delectUpdateInShopImg:(NSString *)fileUrl withIndex:(NSInteger)index{
    BD_WEAKSELF
    [weakSelf.cacheSaveFilePath removeObjectAtIndex:index];
    [self.imageView.collectionView reloadData];
}

-(void)commitInfo{
   [self.view endEditing:YES];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (self.enterpriseType.length == 0){
        showAlert(@"企业类型不能为空");
        return;
    }
    [params setObject:self.enterpriseType forKey:@"enterpriseType"];
   
    if (self.businessLicenseUrl.length == 0) {
        showAlert(@"请上传营业执照");
        return;
    }
    [params setObject:self.businessLicenseUrl forKey:@"businessLicenseUrl"];

    if(self.socialCreditCode.length == 0) {
        showAlert(@"社会信用代码不能为空");
        return;
    }
    [params setObject:self.socialCreditCode forKey:@"socialCreditCode"];

    if (self.enterpriseName.length == 0) {
        showAlert(@"企业名称不能为空");
        return;
    }
    [params setObject:self.enterpriseName forKey:@"enterpriseName"];
//    if (self.enterpriseLocation.length== 0) {
//        showAlert(@"企业所在地不能为空");
//        return;
//    }
//    [params setObject:self.enterpriseLocation forKey:@"enterpriseLocation"];

    if (self.enterpriseAddress.length == 0) {
        showAlert(@"企业详细地址不能为空");
        return;
    }
    [params setObject:self.enterpriseAddress forKey:@"enterpriseAddress"];
   
    if (self.vehicleScale.length == 0) {
        showAlert(@"车辆规模不能为空");
        return;
    }
    [params setObject:self.vehicleScale forKey:@"vehicleScale"];

    if (self.enterprisePhone.length == 0) {
        showAlert(@"对外联系方式不能为空");
        return;
    }
    [params setObject:self.enterprisePhone forKey:@"enterprisePhone"];
//   if (self.proxyStatementUrl.length>0){
//       //授权委托书
//         [params setObject:self.proxyStatementUrl forKey:@"proxyStatementUrl"];
//    }
    if (self.logoUrl.length == 0){
        showAlert(@"请上传公司展示图");
        return;
    }
    [params setObject:self.logoUrl forKey:@"logoUrl"];
    if(self.cacheSaveFilePath.count - 1 == 0){
        showAlert(@"请至少上传一张公司描述图");
        return;
    }
    NSString  * cacheSaveFileArrayStr = [[NSString alloc] init];
    NSMutableArray  *cacheArray=[NSMutableArray array];
    for (int i = 0; i < self.cacheSaveFilePath.count-1; i++) {
        NSString  * cacheString = self.cacheSaveFilePath[i];
        [cacheArray addObject:cacheString];
    }
    for (NSString *string in cacheArray){
        cacheSaveFileArrayStr = [NSString stringWithFormat:@"%@,%@",cacheSaveFileArrayStr,string];
    }
    if (cacheSaveFileArrayStr.length > 0){
        cacheSaveFileArrayStr = [cacheSaveFileArrayStr substringFromIndex:1];
        self.enterprisePhoto = cacheSaveFileArrayStr;
    }
    if (self.enterprisePhoto.length > 0){
        [params setObject:self.enterprisePhoto forKey:@"enterprisePhoto"];
    }
    if (self.transportationLicenseUrl.length > 0) {
        [params setObject:self.transportationLicenseUrl forKey:@"transportationLicenseUrl"];
    }
    if (self.taxiOperationLicenseUrl.length > 0) {
        [params setObject:self.taxiOperationLicenseUrl forKey:@"taxiOperationLicenseUrl"];
    }
    [params setObject:self.detailModel.ID forKey:@"id"];
    
    
    [MSNetworkManager postRevertUrl:Post_Edit_CompanyInfo params:params success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        
        if(isSuccess){
            [self.navigationController popViewControllerAnimated:YES];
        }
        
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
    } withShowHud:YES];
    

    
}

-(void)getdetail{
    
    
//    self.detailModel = [QiYeModel mj_objectWithKeyValues:resonseObj];
    self.enterpriseType = self.detailModel.enterpriseType;
    self.businessLicenseUrl = self.detailModel.businessLicenseUrl;
    self.enterpriseName = self.detailModel.enterpriseName;
    self.socialCreditCode = self.detailModel.socialCreditCode;
    self.enterpriseLocation = self.detailModel.enterpriseLocation;
    self.enterpriseAddress = self.detailModel.enterpriseAddress;
    self.vehicleScale = self.detailModel.vehicleScale;
    self.enterprisePhone = self.detailModel.enterprisePhone;
    self.logoUrl = self.detailModel.logoUrl;
    self.enterprisePhoto = self.detailModel.enterprisePhoto;
    self.proxyStatementUrl = self.detailModel.proxyStatementUrl;
    self.transportationLicenseUrl = self.detailModel.transportationLicenseUrl;
    self.taxiOperationLicenseUrl = self.detailModel.taxiOperationLicenseUrl;
    [self createUploadImage];
    [self.tableView reloadData];
    
//    [MSNetworkManager postRevertUrl:POST_Company_Detail_Url params:@{} success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
//
//        if(isSuccess){
//            self.detailModel = [QiYeModel mj_objectWithKeyValues:resonseObj];
//            self.enterpriseType = self.detailModel.enterpriseType;
//            self.businessLicenseUrl = self.detailModel.businessLicenseUrl;
//            self.enterpriseName = self.detailModel.enterpriseName;
//            self.socialCreditCode = self.detailModel.socialCreditCode;
//            self.enterpriseLocation = self.detailModel.enterpriseLocation;
//            self.enterpriseAddress = self.detailModel.enterpriseAddress;
//            self.vehicleScale = self.detailModel.vehicleScale;
//            self.enterprisePhone = self.detailModel.enterprisePhone;
//            self.logoUrl = self.detailModel.logoUrl;
//            self.enterprisePhoto = self.detailModel.enterprisePhoto;
//            self.proxyStatementUrl = self.detailModel.proxyStatementUrl;
//            self.transportationLicenseUrl = self.detailModel.transportationLicenseUrl;
//            self.taxiOperationLicenseUrl = self.detailModel.taxiOperationLicenseUrl;
//            [self createUploadImage];
//            [self.tableView reloadData];
//        }
//
//    } failure:^(NSUInteger code, NSString * _Nonnull message) {
//    } withShowHud:YES];
    
}
-(void)getCheLiangGuiMo{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:@"CLGM" forKey:@"code"];
    
    NSString *url = [NSString stringWithFormat:@"%@?code=CLGM",CarDetailDict];
    [MSNetworkManager postRevertUrl:url params:params success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        
        if(isSuccess){
            NSArray  *  cacheArray = resonseObj;
             self.vehicleScaleArray = [JueSeModel  mj_objectArrayWithKeyValuesArray:cacheArray];
        }
        
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
        
    } withShowHud:NO];
    

}
@end
